home *** CD-ROM | disk | FTP | other *** search
- Path: flute.aix.calpoly.edu!not-for-mail
- From: mporcell@flute.aix.calpoly.edu (Michael Anthony Porcelli)
- Newsgroups: comp.lang.c++
- Subject: Re: Can copy constructor and operator= share code?
- Date: 6 Mar 1996 05:18:41 -0800
- Organization: California Polytechnic State University, San Luis Obispo
- Message-ID: <4hk3bh$1j4s@flute.aix.calpoly.edu>
- References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM> <199603040709.a35476@iz.maus.de>
- NNTP-Posting-User: mporcell@flute.aix.calpoly.edu
-
- Here's a style tip from a senior level C++/OO class on exactly this topic.
- In fact our teacher *required* this for all of our classes and frankly I
- believe this is a GREAT C++ tip for good OO/SoftEng.
-
- Every class should have 2 private/protected member functions called Delete
- and Duplicate (or something to that effect). Duplicate should take a class&
- (just like the copy constructor). Now, code re-use is easy, watch...
-
- X(X& x)
- { Duplicate(x); } //one-statement, in-line copy constructor.
-
- operator= (X& x)
- { Delete(); Duplicate(x); } //two-statement, in-line op=
-
- ~X()
- { Delete(); } //one-statement, in-line destructor.
-
- Pretty nifty, eh? I believe that all class design should be done this way.
-
- -Mike
-
-
-
-
-